<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>后台管理</title>
 </head>
<body>
<rms:role operateCode="html_search">
	<form id="searchForm">
		<table>
			<tr>
				<td>订单号：</td><td><input type="text" class="control-text" name="orderIdSch"></td>
				<td>手机号：</td><td><input type="text" class="control-text" name="mobileSch"></td>
				<td>地址：</td><td><input type="text" class="control-text" name="addressSch"></td>
			</tr>
		</table>
		<button  type="button" id="schBtn" class="button button-primary">搜索</button>
	</form>
	<hr>
	<div class="grid-bar">
		<rms:role operateCode="btn_add">
			<button  type="button" id="addBtn" class="button button-primary">新增</button>
		</rms:role>
		<rms:role operateCode="btn_export">
			<button  type="button" id="exportBtn" class="button button-primary">导出</button>
		</rms:role>
	</div>
	
	<div id="grid"></div>
  
   <div id="dlg" class="hide">
      <form id="editForm">
      	<input type="hidden" name="orderId">
      	<table>
      		<tr>
      			<th><s>*</s>手机号</th><td>
      				<input name="mobile" type="text" 
      				rules="[
      					{rule:{notNull:true},errorMsg:'不能为空'}
					]"
				 	class="input-normal control-text"></td>
      		</tr>
      		<tr>
      			<th><s>*</s>城市名</th><td>
      				<input name="cityName" type="text" 
					 rules="[
      					{rule:{notNull:true},errorMsg:'不能为空'}
					]"
					 class="input-normal control-text"></td>
      		</tr>
      		<tr>
      			<th>地址</th><td><input name="address" type="text" data-rules="{required:true}" class="input-normal control-text"></td>
      		</tr>
      		<tr>
      			<th><s>*</s>下单时间</th><td>
      				<input id="createDate" name="createDate" type="text" 
      				rules="[
      					{rule:{notNull:true},errorMsg:'不能为空'}
					]" 
      				class="input-normal control-text"></td>
      		</tr>
      	</table>
      </form>
    </div>
  
<script type="text/javascript">

VUI.use(['PageForm'],function(){
	var listUrl = ctx + 'listEasyuiOrderInfo.do'; // 查询
	var addUrl = ctx + 'addEasyuiOrderInfo.do'; // 添加
	var updateUrl = ctx + 'updateEasyuiOrderInfo.do'; // 修改
	var delUrl = ctx + 'delEasyuiOrderInfo.do'; // 删除
	var exportUrl = ctx + 'exportOrderInfo.do'; // 导出
	var $schBtn = $('#schBtn'); // 查询按钮
	var $addBtn = $('#addBtn'); // 添加按钮
	var $exportBtn = $('#exportBtn');
	
	var grid; // 表格
	var schForm,pageForm; 
	var dialog;// 编辑表单

    function init() {
    	initEditing();
    	initGrid();
    	initEvent();
    	initForm();
    }
    
    function initForm() {
	    schForm = new VUI.Form({formId:'searchForm'});
	    
	    pageForm = new VUI.PageForm({
			formId:'editForm'
			,grid:grid
			,win:dialog
			,crudUrl:{
				add:addUrl
				,update:updateUrl
				,del:delUrl
			}
		});
	    
	    new VUI.DatePick({targetId:"createDate"});
    }
    
    function initEditing() {
    	dialog = new VUI.Dialog({
			contentId:'dlg'
            ,onOk:function(){
            	save();
            }
		});
    }
    
    function initGrid() {
    	
    	grid = new VUI.Grid({
          	renderId:'grid'
          	,url:listUrl
          	,columns : [[
   	    	   {title:'订单编号',field:'orderId'}
   	          ,{title:'手机号',field:'mobile'}
   	          ,{title:'城市名',field:'cityName'}
   	          ,{title:'地址',field:'address'}
   	          ,{title:'下单时间',field:'createDate'}
   	          ,{title:'操作',field:'',width:200,formatter : function(value,obj){
   	       	   	  var updateStr = '<span class="grid-command btn-edit">修改</span>';
   	              var delStr ='<span class="grid-command btn-del">删除</span>';
   	              return RightUtil.auth('grid_edit',updateStr,'') + RightUtil.auth('grid_del',delStr,'');
   	            }}
   	        ]]
	    	,striped:true // 斑马线
			,pagination :true
			,rownumbers :true
    	});

    }
    
    function initEvent() {
        grid.on('ClickCell',function(ev){
        	var sender = $(ev.target); //点击的Dom
        	if(sender.hasClass('btn-del')){
            	var record = ev.row;
            	del(record);
        	}
        	if(sender.hasClass('btn-edit')){
            	var record = ev.row;
            	edit(record);
        	}
        });
        
    	$schBtn.on('click',function(ev){
           search();
    	});
    	
    	$addBtn.on('click',function(ev){
           add();
    	});
    	
    	$exportBtn.on('click',function(ev){
    		exportFile();
    	});
    }
    
    
    //////// functions ////////
    
    function search() {
    	grid.load(schForm.getData());
    }
    
    function exportFile() {
    	var data = schForm.getData();
    	ExportUtil.doExport(exportUrl,data);
    }
    
    function save() {
    	pageForm.save();
    }
    
    function add(){
    	pageForm.add();
    }
    
    function edit(record) {
    	pageForm.update(record);
    }
    
    function del(record){
    	pageForm.del(record);
    }
    
    init();
	
});

</script>
</rms:role>
</body>
</html>